<template>
  <div class="page">
    <div class="weui-cells odetail">
      <div class="weui-cell">
        <div class="weui-cell__bd">{{orderId}}</div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__bd grey">
          <div>订单日期：{{result.orderTime}}</div>
          <div>订单来源：{{result.orderType}}</div>
          <div>订单类型：{{result.orderFlagName}}</div>
          <div>支付方式：{{result.paySourceName}}</div>
          <div>订单产品：</div>
        </div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <div class="weui-flex pitem grey" v-for="(item,index) in result.details" :key="index">
            <div class="weui-flex__item">{{item.product.spName}}</div>
            <div class="number">x{{item.product.yxbj}}</div>
            <div class="number">次</div>
            <div class="price">¥{{item.amount*0.01}}</div>
          </div>

        </div>
      </div>
      <div class="weui-cell">
        <div class="weui-cell__bd total">合计：<span>¥{{result.amount*0.01}}</span></div>
      </div>
    </div>
  </div>
</template>

<script>
import card from '@/components/card'
 import * as appId from "@/utils/util"
 import {getTIme} from "@/utils/util"
export default {
  data () {
    return {
      current: 0,
      userId:"",
      phone:"",
      id:"",
      result:{},
      paySource:[{
        name:"pos销售支付(线下)",
        value:1
      },{
        name:"微信线上支付",
        value:2
      },{
        name:"支付宝线上支付",
        value:3
      }],
      orderFlag:[{
        name:"充值单",
        value:0
      },{
        name:"首单",
        value:1
      },{
        name:"翻单",
        value:2
      },{
        name:"体验单",
        value:3
      },{
        name:"线上单",
        value:4
      },{
        name:"赠送单",
        value:5
      },{
        name:"门店开单",
        value:6
      }],
      listLabel:[{
        name:"门店",
        value:1
      },{
        name:"小程序",
        value:2
      },{
        name:"公众号",
        value:3
      },{
        name:"微商城",
        value:4
      }],
      orderId:""
    }
  },
  components: {
    card
  },
  onLoad(option){
    this.id=option.id;
    this.orderId=option.ordId
  },
  onShow(){
    wx.setNavigationBarTitle({
      title: "订单详情"
    })
    this.userInfo =wx.getStorageSync('userInfo')&&JSON.parse(wx.getStorageSync('userInfo'))
    if(this.userInfo) {
      this.phone=this.userInfo.mobileNo;
      this.userId=this.userInfo.baseUserId;
      this. getDetail()



    }else{
      wx.showToast({
        title:'请先登录',
        icon: 'none',
        duration: 2000
      })
    }
  },
  methods: {
    getDetail(){
      this.$http.request({
                method:"post",
                url:"/v1.0/appletLogin/orderDetail",
                body:{

      					   "orderId":this.orderId
      				   }
      }).then((data)=>{
        if(data.code==0){
          this.result=data.result;
          this.result.orderTime=getTIme(this.result.orderTime)
          this.result.details.forEach((a,i)=>{
            this.result.paySource=a.saleOrder.paySource;
            let paySource=this.paySource.filter((item)=>{
              return item.value==this.result.paySource;
            })[0];
            if(paySource){
              this.result.paySourceName=paySource.name;
            }
            this.result.orderSource=a.saleOrder.orderSource;
            this.result.orderFlag=a.saleOrder.orderFlag;
            let arrOrderFlag=this.orderFlag.filter((item)=>{
              return item.value==this.result.orderFlag;
            })[0];
            if(arrOrderFlag){
              this.result.orderFlagName=arrOrderFlag.name;
            }
            let arr=this.listLabel.filter((item)=>{
              return item.value==this.result.orderSource
            })[0]
            if(arr){
              this.result.orderType=arr.name;
            }
          })
          // this.result.createTime=getTIme(this.result.createTime)
        }
      })
    },
    bindViewTap () {
      const url = '../logs/main'
      if (mpvuePlatform === 'wx') {
        mpvue.switchTab({ url })
      } else {
        mpvue.navigateTo({ url })
      }
    }
  },

  created () {
    // let app = getApp()
  }
}
</script>

<style scoped>
.odetail{
  font-size: 0.8em;
}
.pitem .number{
  width: 3em;
  text-align: center;
}
.pitem .price{
  color: #E4393C;
  width: 5em;
  text-align: right;
}
.total{
  color: #E4393C;
  text-align: right;
}
</style>
